<script lang="ts" setup>
import { reactive, ref } from 'vue'
import {ElMessage, FormItemProps, FormProps} from 'element-plus'
import axios from '../axios/index'
import {useRoute} from "vue-router";
import router from '../router/index'

const route = useRoute()
let openId = ref(route.query.openId)
const labelPosition = ref<FormProps['labelPosition']>('right')
const itemLabelPosition = ref<FormItemProps['labelPosition']>('')
const formLabelAlign = reactive({
  studentId: '202400025',//学号
  password:'123456',//密码
  openId:openId.value//openId
})
//提交绑定
function submitForm() {
  axios.post('/student/bindStudentId',{
    studentId:formLabelAlign.studentId,
    password: formLabelAlign.password,
    openId:formLabelAlign.openId,
  }).then((response) => {
    console.log(response.data)
    if (response.data.code === 200) {
      ElMessage({
        type: 'success',
        message:response.data.message,
      })
      router.push('/login')
    }
  }).catch(error => {
    ElMessage({
      type: 'error',
      message:error.message,
    })
  })
}
//重置信息
function resetForm() {
  formLabelAlign.studentId=''
  formLabelAlign.password=''
}
</script>

<template>
  <el-form
      :label-position="labelPosition"
      label-width="auto"
      :model="formLabelAlign"
      style="max-width: 600px;margin:20% auto;"
  >
    <el-form-item label="学号：" :label-position="itemLabelPosition">
      <el-input type="text" size="default" v-model="formLabelAlign.studentId" placeholder="请输入要绑定的学号" style="width: 300px"/>
    </el-form-item>
    <el-form-item label="密码：" :label-position="itemLabelPosition">
      <el-input type="password" size="default" v-model="formLabelAlign.password" placeholder="请输入密码" style="width: 300px"/>
    </el-form-item>
    <el-form-item style="margin: 5% 30%">
      <el-button type="primary" @click="submitForm()">
        绑定
      </el-button>
      <el-button @click="resetForm()">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<style scoped>

</style>